<template>
    <div>
       <h2>用药信息修改</h2>
       <table class="table table-bordered">
        <tbody>
            <tr>
                <td align="right">药品名称</td>
                <td>
                    <input type="text" v-model="query.serciesName"/>
                </td>
            </tr>
            <tr>
                <td align="right">科室</td>
                <td>
                    <select v-model="query.differentName">
                        <option value="">请选择</option>
                        <option :value="item.differentName" v-for="item in dif">{{ item.differentName }}</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">用药日期</td>
                <td>
                    <input type="date" v-model="query.useTime"/>
                </td>
            </tr>
            <tr>
                <td align="right">病人姓名</td>
                <td>
                    <input type="text" v-model="query.userName"/>
                </td>
            </tr>
            <tr>
                <td align="right">病房号码</td>
                <td>
                    <input type="text" v-model="query.serNumber"/>
                </td>
            </tr>
            <tr>
                <td align="right">用药状态</td>
                <td>
                    <input type="radio" name="sta"  :value="0" v-model="query.state"/>已完成
                    <input type="radio" name="sta"  :value="1" v-model="query.state"/>未开始
                </td>
            </tr>
            <tr>
                <td align="right">配药医生</td>
                <td>
                    <input type="text" v-model="query.doctorName"/>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="修改" class="btn btn-primary" @click="ok"/>
                </td>
            </tr>
        </tbody>
       </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { ref,reactive,onMounted } from 'vue';
import { useRoute,useRouter } from 'vue-router';
const router=useRouter();
const route=useRoute();

onMounted(()=>{
    showdif();
    Fan();
})

let dif:any=ref([])

const showdif=()=>
{
  axios
  ({
    url:'/api/Diff/ShowDiff',
    method:'get'
  })
  .then(res=>{
    dif.value=res.data;
  })
  .catch(err=>{

  })
}

let query:any=reactive
({
    "serciesId": route.query.id,
  "serciesName": "",
  "differentName": "",
  "useTime": "",
  "userName": "",
  "serNumber": "",
  "state": 0,
  "doctorName": ""
})
//反填
const Fan=()=>
{
    axios
    ({
        url:'/api/Diff/SerFan',
        method:'get',
        params:
        {
            id:route.query.id
        }
    })
    .then(res=>{
        Object.assign(query,res.data);
        query.useTime=query.useTime.substring(0,10);
    })
    .catch(err=>{

    })
}

//修改
const ok=()=>
{
    if(query.serciesName=="")
    {
        alert("药品名称不能为空");
        return;
    }
    if(query.differentName=="")
    {
        alert("科室名称不能为空");
        return;
    }
    if(query.useTime=="")
    {
        alert("用药日期不能为空");
        return;
    }
    if(query.userName=="")
    {
        alert("病人姓名不能为空");
        return;
    }
    if(query.serNumber=="")
    {
        alert("病房号码不能为空");
        return;
    }
    if(query.doctorName=="")
    {
        alert("配药医生不能为空");
        return;
    }
    axios
    ({
        url:'/api/Diff/SerUpdate',
        method:'put',
        data:query
    })
    .then(res=>{
        if(res.data>0)
        {
            alert("修改成功");
            router.push('/serList');
            return;
        }
        else
        {
            alert("修改失败");
            return;
        }
    })
    .catch(err=>{

    })
}


</script>

<style scoped>

</style>